package com.audition.thread;

import sun.misc.PostVMInitHook;

/**
 * @author ADMIN
 * @date 2021/3/7 23:34
 */
public class VolatileCanStop implements Runnable {
    private volatile boolean canceled = false;

    @Override
    public void run() {
        int num = 0;
        while (!canceled && num <= 100000) {
            if (num % 10 == 0) {
                System.out.println(num + "是10 的倍数");
                num++;
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();

                }

            }


        }
    }

    public static void main(String[] args) throws InterruptedException {
        VolatileCanStop volatileCanStop = new VolatileCanStop();
        Thread thread = new Thread(volatileCanStop);
        thread.start();
        Thread.sleep(3000);
        volatileCanStop.canceled = true;

    }
}
